import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 区域信息 */
export interface CompanyArea {
  id: number // 区域id
  name?: string // 区域名称
  parentId?: number // 上级区域
  sort?: number // 显示顺序
  dutyUserId: string // 负责人
  dutyUserName?: string // 负责人
  status?: number // 状态
  children?: CompanyArea[]
}

// 区域 API
export const CompanyAreaApi = {
  // 查询区域列表
  getCompanyAreaList: async (params) => {
    return await request.get({ url: `/business/company-area/list`, params })
  },

  // 查询区域详情
  getCompanyArea: async (id: number) => {
    return await request.get({ url: `/business/company-area/get?id=` + id })
  },

  // 新增区域
  createCompanyArea: async (data: CompanyArea) => {
    return await request.post({ url: `/business/company-area/create`, data })
  },

  // 修改区域
  updateCompanyArea: async (data: CompanyArea) => {
    return await request.put({ url: `/business/company-area/update`, data })
  },

  // 删除区域
  deleteCompanyArea: async (id: number) => {
    return await request.delete({ url: `/business/company-area/delete?id=` + id })
  },

  // 导出区域 Excel
  exportCompanyArea: async (params) => {
    return await request.download({ url: `/business/company-area/export-excel`, params })
  }
}
